package org.yfh.controller;

import io.swagger.annotations.Api;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yfh.common.Result;
import org.yfh.common.page.Page;
import org.yfh.service.dto.SearchParamInputDTO;
import org.yfh.model.Sku;
import org.yfh.service.SkuEsAggregateService;
import org.yfh.service.SkuEsSearchService;
import org.yfh.service.vo.AggregateResultVO;
import org.yfh.service.dto.SkuEsInputDTO;

@RequestMapping("product")
@RestController
@RequiredArgsConstructor
@Api("商品")
public class SkuSearchController {
  private final SkuEsSearchService skuEsService;
  private final SkuEsAggregateService skuEsAggregateService;

  @PostMapping(value = "")
  public Result<Object> onSale(@RequestBody List<SkuEsInputDTO> skuList) {
    skuEsService.onSale(skuList);
    return Result.success();
  }

  @GetMapping("")
  public Result<Page<Sku>> advanceSearch(SearchParamInputDTO searchParamInputDTO) {
    return Result.success(skuEsService.advanceSearch(searchParamInputDTO));
  }

  @GetMapping("aggregate")
  public Result<AggregateResultVO> aggregate(String keyword) {
    return Result.success(skuEsAggregateService.aggregate(keyword));
  }
}
